import {useSettingStore} from "stores/setting-store.js";
import {changeUnit} from "src/utils/tool.js";
import {MAP_URL} from "src/constant/data.js";
import * as turf from '@turf/turf'
const settingStore = useSettingStore();
const  measureDistance=(polyLine,unit) => {
  let line = polyLine.toGeoJSON()
  console.log(line)
  let distance= turf.length(line, {units: unit});
  console.log(distance)
  return distance
}
const measureArea=(polygon, unit) => {
  let polygonGeojson = polygon.toGeoJSON()
  console.log(polygonGeojson)
  return  turf.area(polygonGeojson, {units: unit});
}
export const getDistance = async (polyLine) => {
  let unit = settingStore.map.unit
  let distance = measureDistance(polyLine,settingStore.map.unit)

  console.log(distance)
  polyLine.bindTooltip(distance.toFixed(settingStore.map.decimal) + ' ' + '米').openTooltip()
}
export const getArea = (polygon) => {
  let unit = settingStore.map.unit

  let area =  measureArea(polygon,unit)

  polygon.bindTooltip(area.toFixed(settingStore.map.decimal) + ' ' + '平方米').openTooltip()
}
